#delimit;
clear all;
version 13.1;
pause on;
program drop _all;
capture log close;
set more off;

/*INSERT FOLDER PATH*/
cd /;


use retractions_descriptives.dta, clear;

/**/
foreach defn in all loose strct {;

estimates drop _all;
quietly estpost tabstat srce_year rtrct_year rtrct_speed nbrelated partofacase strng_shoulders shaky_shoulders absnt_shoulders yes_malice dbt_malice non_malice bigfraud lvl_penalty log_penalty stk_srce_cites us_rpa if subv_of_trth_`defn'==1, stat(mean p50 sd min max count) c(s);
esttab, cells("mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label;
esttab using tables/retractions_desc_stats_srce_pmid_`defn'.rtf, cells("mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) 
sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label replace;

};


tab partofacase;
distinct case_code;
egen nbretractions=nvals(srce_pmid), by(case_code);


bysort case_code: keep if _n==_N;
keep case_code nbretractions;
tab nbretractions;
bysort nbretractions: drop if _n>100;
twoway histogram nbretractions, freq discrete yaxis(1) title(" ") legend(off) ylabel(0(10)100, angle(horizontal) format(%15.0fc)) xtitle("  ") xlabel(1 2 5 10 15 20 25, labsize(small)) lwidth(none) saving(graphs/nbretractions_strct.gph, replace);

